<template>
  <section class="cms-body" v-loading="loading">
    <!-- 返回组件 -->
    <cms-back></cms-back>
    <el-form ref="form" :model="dataInfo" :rules="rules" class="cms-form" label-width="162px">

      <el-form-item label="id" class="flex-50" prop="keywordName">
        <el-input v-model="dataInfo.userId" class="cms-width" :disabled="true"></el-input>
      </el-form-item>

      <el-form-item label="姓名" class="flex-50" prop="userName">
        <el-input v-model="dataInfo.userName" class="cms-width"></el-input>
      </el-form-item>

      <el-form-item label="昵称" class="flex-50" prop="nickName">
        <el-input v-model="dataInfo.nickName" class="cms-width"></el-input>
      </el-form-item>

      <el-form-item label="性别" class="flex-50" prop="isDisabled">
        <el-radio-group v-model="dataInfo.sex">
          <el-radio :label="0">保密</el-radio>
          <el-radio :label="1">女</el-radio>
          <el-radio :label="2">男</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="状态" class="flex-50" prop="isDisabled">
        <el-radio-group v-model="dataInfo.status">
          <el-radio :label="0">禁用</el-radio>
          <el-radio :label="1">启用</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="手机号码" class="flex-50" prop="mobile">
        <el-input v-model="dataInfo.mobile" class="cms-width" :disabled="true"></el-input>
      </el-form-item>

      <el-form-item label="邮箱" class="flex-50" prop="email">
        <el-input v-model="dataInfo.email" class="cms-width" :disabled="true"></el-input>
      </el-form-item>

      <el-form-item label="出生日期" class="flex-50">
        <el-date-picker v-model="dataInfo.birthday" type="date" class="cms-width" value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>

    </el-form>
    <div class="form-footer">
      <el-button type="warning" v-if="isType('save')" @click="add(true)">提交并继续添加
      </el-button>
      <el-button type="primary" v-if="isType('save')" @click="add(false)">添加
      </el-button>
      <el-button type="primary" v-if="isType('update')" @click="update()" v-perms="'/appUser/update'">修改
      </el-button>
      <el-button type="info" @click="$reset">重置</el-button>
      <span class="gray" v-if="isType('save')">选择“提交并继续添加”按钮会停留在添加页面；选择“提交”按钮后将跳转到对应的列表页</span>
    </div>
  </section>
</template>
<script>
  import axios from "axios";
  import va from "@/rules";
  import formMixns from "@/mixins/form";

  export default {
    mixins: [formMixns],
    data() {
      return {
        rules: {
        },
        dataInfo: {}
      };
    },
    methods: {
      getDataInfo(id, type) {
        if (type == 'update') {
          let api = this.$api; //API地址
          axios.all([
            axios.post(api.appUserGet, {userId: id}),
          ]).then(axios.spread((res) => {
            this.loading = false;
            this.$refs["form"].resetFields();
            this.dataInfo = res.body; //将用户数据复制给dataInfo
          })).catch(error => {
            this.loading = false;
          });
        }
        this.loading = false;
      },
      add(state) {
        this.saveDataInfo(state, this.$api.appUserSave, this.dataInfo, "pageList");
      },
      update() {
        this.updateDataInfo(this.$api.appUserUpdate, this.dataInfo, "pageList");
      }
    },
    created() {
      this.getDataInfo(this.id, this.type);//初始获取数据
    }
  };
</script>

<style>
</style>
